Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.Compatibility.VB6
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Imports Microsoft.VisualBasic.PowerPacks

Friend Class FRMmain

    Inherits System.Windows.Forms.Form
    Public aColumnWidths As Object
    Public Adodc1 As ADODC = New ADODC
    Public bRemoteSaved As Boolean
    Public uniqueIDindex As Short

    Private doRemoteUpdate, boolAddrow As Boolean

    Dim matchPhrase, matchCase As String
    Dim strColumnWidths As Object

    Dim Ymouse, Xmouse As Short

    Dim fso As Scripting.FileSystemObject

    ' Form load event -------------------------------------------------------------------------------------------------------------------------------

    Private Sub FRMmain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

        On Error Resume Next

        bRemoteSaved = True

        ' Set display properties ----------------------------------------------------------------------------------------

        editMenu.Visible = False

        MODdbMethods.init()
        MODweb.init()

        initPreferences()

        ' Check that remote update directory exists and create it if it doesn't. ---------------------------------------------------------------

        fso = New Scripting.FileSystemObject

        If Not fso.FolderExists(MODweb.sRemoteUpdateDirPath) Then fso.CreateFolder(MODweb.sRemoteUpdateDirPath)
        If Not fso.FolderExists(MODweb.sRemoteUpdateBackupDirPath) Then fso.CreateFolder(MODweb.sRemoteUpdateBackupDirPath)

    End Sub

    ' Resize -------------------------------------------------------------------------------------------------------------------------

    'UPGRADE_WARNING: Event FRMmain.Resize may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
    Private Sub FRMmain_Resize(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Resize

        On Error Resume Next

        If ClientRectangle.Width > 300 Then

            DataGrid.Width = ClientRectangle.Width - 17
            DataGrid.Height = ClientRectangle.Height - DataGrid.Top - 10

            Line1.X2 = VB6.TwipsToPixelsX(ClientRectangle.Width)

        End If

    End Sub

    ' Set the widths of the dataGrid columns according to the registry preferences -----------------------------------------------------------------------------------

    Public Sub setDataGridColumnWidths()
        Dim i As Object
        Dim r As Object
        Dim fld As Object

        ' Get preferences from registry --------------------------------------------------------------------------------

        'UPGRADE_WARNING: Couldn't resolve default property of object getPref(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        'UPGRADE_WARNING: Couldn't resolve default property of object strColumnWidths. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        strColumnWidths = getPref("", "columnWidths")

        ' In case there are no column widths saved --------------------------------------------------------------------

        'UPGRADE_WARNING: Couldn't resolve default property of object strColumnWidths. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        If strColumnWidths = "" Then

            'UPGRADE_WARNING: Couldn't resolve default property of object r.Fields. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            For Each fld In r.Fields

                'UPGRADE_WARNING: Couldn't resolve default property of object strColumnWidths. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                strColumnWidths = strColumnWidths & "100,"

            Next fld

            setPref("", "columnWidths", strColumnWidths)

        End If

        'UPGRADE_WARNING: Couldn't resolve default property of object strColumnWidths. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        'UPGRADE_WARNING: Couldn't resolve default property of object aColumnWidths. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        aColumnWidths = Split(strColumnWidths, ",")

        'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        i = 0

        ' Set dataGrid column widths according to preferences in registry --------------------------------------------------------------------------

        'UPGRADE_WARNING: Couldn't resolve default property of object FRMmain.Adodc1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        For Each fld In Me.Adodc1.Recordset.Fields

            'UPGRADE_WARNING: Couldn't resolve default property of object aColumnWidths(i). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            'UPGRADE_WARNING: Couldn't resolve default property of object aColumnWidths(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            Me.DataGrid.Columns(i).Width = VB6.TwipsToPixelsX(aColumnWidths(i))

            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            i = i + 1

        Next fld

    End Sub

    Private Sub editPreferences_Click()

        DLGpreferences.Show()

    End Sub

    Public Sub editAddRow_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles editAddRow.Click
        Dim uniqueID As Object
        Dim objField As Object
        Dim Adodc1 As Object

        On Error GoTo errorHandler

        boolAddrow = True
        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        Adodc1.Recordset.AddNew()

        '' SET A DEFAULT VALUE FOR ALL FIELDS
        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        For Each objField In Adodc1.Recordset.Fields
            'UPGRADE_WARNING: Couldn't resolve default property of object objField.Value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            objField.Value = 0
        Next objField

        'UPGRADE_WARNING: Couldn't resolve default property of object uniqueID. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        uniqueID = "part_" & getUniqueTimeStamp() & "_" & uniqueIDindex
        uniqueIDindex = uniqueIDindex + 1
        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        'UPGRADE_WARNING: Couldn't resolve default property of object uniqueID. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        Adodc1.Recordset("uniqueID") = uniqueID
        isNewRecord = True
        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        MODweb.buildUpdateStatement(Adodc1.Recordset, "INSERT")

        Exit Sub

errorHandler:

        If Err.Number = 91 Then MsgBox("There is no open DataBase")

        'debug.print Err.Number
    End Sub

    Public Sub editCopyRow_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles editCopyRow.Click

        On Error Resume Next

        copyRow()

    End Sub

    Public Sub editDeleteRow_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles editDeleteRow.Click
        Dim Adodc1 As Object

        On Error GoTo errorHandler

        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        MODweb.buildUpdateStatement(Adodc1.Recordset, "DELETE")

        Me.TXTsearch.Focus() ' this takes the focus away from the datagrid and prevents an error message from the datagrid

        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        Adodc1.Recordset.Delete()

errorHandler:
        If Err.Number = 91 Then MsgBox("There are no rows to delete")
        'debug.print Err.Number
    End Sub

    Private Sub initPreferences()

        On Error Resume Next

        With New regOp

            .Root = regOp.RegRoot.HKEY_LOCAL_MACHINE
            .Key = "Software\bbd\AccessSearch"

            '======================================================================================='
            ' Install Initial Values in the registry, in case they do not exist already             '
            '======================================================================================='
            setDefaultPrefs()

        End With

    End Sub

    '-------------------------------------------'
    '   copy row from dataGrid to clipboard     '
    '-------------------------------------------'
    Private Sub copyRow()
        Dim splRowVal As Object
        Dim splHeaders As Object
        Dim fld As Object
        Dim selVal As Object
        Dim c As Object

        On Error GoTo handleError

        Dim hasRecords As Boolean
        For Each c In DataGrid.Columns
            'UPGRADE_WARNING: Couldn't resolve default property of object c.Text. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            If c.Text <> "" Then
                hasRecords = True
                Exit For
            End If
        Next c
        Dim rs As ADODB.Recordset
        'Dim objDoc As Microsoft.Office.Interop.Word.Document
        Dim rowVal, headers As String
        Dim i As Short
        If hasRecords Then
            'UPGRADE_WARNING: Couldn't resolve default property of object selVal. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            selVal = ""
            'UPGRADE_WARNING: Couldn't resolve default property of object FRMmain.Adodc1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            rs = Me.Adodc1.Recordset
            For Each fld In rs.Fields
                'UPGRADE_WARNING: Couldn't resolve default property of object fld.Name. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                headers = headers & "|" & fld.Name
            Next fld
            For Each c In DataGrid.Columns
                'UPGRADE_WARNING: Couldn't resolve default property of object c.Text. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                rowVal = rowVal & "|" & c.Text
                i = i + 1
            Next c
            ' objDoc = New Microsoft.Office.Interop.Word.Document
            'objDoc.Activate()
            'objDoc.Tables.Add(objDoc.Range, 2, i)
            'UPGRADE_WARNING: Couldn't resolve default property of object splHeaders. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            splHeaders = Split(headers, "|")
            For i = 0 To UBound(splHeaders)
                'UPGRADE_WARNING: Couldn't resolve default property of object splHeaders(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                '    objDoc.Tables.Item(1).Cell(1, i + 1).Range.Text = splHeaders(i)
            Next
            'UPGRADE_WARNING: Couldn't resolve default property of object splRowVal. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            splRowVal = Split(rowVal, "|")
            For i = 0 To UBound(splRowVal)
                'UPGRADE_WARNING: Couldn't resolve default property of object splRowVal(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                '    objDoc.Tables.Item(1).Cell(2, i + 1).Range.Text = splRowVal(i)
            Next
            My.Computer.Clipboard.Clear()
            'objDoc.Range.Copy()
            'objDoc.Close(False)
            'UPGRADE_NOTE: Object objDoc may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
            'objDoc = Nothing
        End If

handleError:
        'debug.print Err.Number
        If Err.Number = 7005 Then MsgBox("There are no rows to copy")
        Exit Sub
    End Sub
    '---------------------------------------'
    '   delete a row in the dataGrid          '
    '---------------------------------------'
    Private Sub deleteRow()
        Dim i As Object
        Dim Adodc1 As Object

        On Error Resume Next

        Dim deleteStr As String

        Dim rs As ADODB.Recordset
        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        rs = Adodc1.Recordset

        deleteStr = "DELETE * FROM " & VB6.GetItemString(Me.LISTtables, Me.LISTtables.SelectedIndex) & " WHERE [" & rs.Fields(0).Name & "] = '" & rs.Fields(0).Value & "'"

        For i = 1 To rs.Fields.Count - 1
            deleteStr = deleteStr & " AND [" & rs.Fields(i).Name & "] = '" & rs.Fields(i).Value & "'"
        Next
        rs.Close()
        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.RecordSource. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        Adodc1.RecordSource = deleteStr
        MsgBox(deleteStr)
        'rs.Open deleteStr
        'DataGrid.Refresh
handleError:
        Exit Sub
    End Sub
    '---------------------------------------'
    '   Menu > Import click event           '
    '---------------------------------------'
    'Private Sub fileImport_Click()
    'On Error GoTo handleError
    '    CommonDialog.ShowOpen
    '    With CommonDialog
    '        DLGimport.Show
    '        DLGimport.TEXTimportFileName.Text = .FileName
    '        MODdbMethods.setImportTablesCombo .FileName
    '    End With
    'handleError:
    '    If Err.Number = -2147217842 Then
    '        DLGimport.Hide
    '        Exit Sub
    '    End If
    'End Sub
    '---------------------------------------'
    '   Menu > Export Click event           '
    '---------------------------------------'
    Public Sub fileExportToExcel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles fileExportToExcel.Click

        On Error Resume Next

        If LISTtables.SelectedIndex < 0 Then

            MsgBox("There is no open database to export")

            Exit Sub

        End If

        DLGexport.ShowDialog()

    End Sub
    '---------------------------------------'
    '   Menu > Open Click event             '
    '---------------------------------------'
    Public Sub fileOpen_Renamed_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles fileOpen_Renamed.Click

        On Error GoTo errorHandler

        'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
        With CommonDialogOpen

            'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            .Filter = "Access Databases (*.mdb)|*.mdb|All Files|*.*"

            .ShowDialog()
            MODdbMethods.DatabasePath = .FileName
            MODdbMethods.SetTables(.FileName)

        End With

errorHandler:

        Select Case Err.Number

            Case 32755 ' Cancel was selected

                Exit Sub

        End Select

    End Sub


    Public Sub filePrint_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles filePrint.Click
        Dim Printer As New Printer
        Dim intCols As Object
        Dim intRows As Object

        On Error Resume Next

        'UPGRADE_WARNING: Couldn't resolve default property of object intRows. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        intRows = 1
        'UPGRADE_WARNING: Couldn't resolve default property of object intCols. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        intCols = 1
        On Error GoTo printErrorHandler
        Printer.Orientation = 2
        Throw New NotImplementedException
        Printer.EndDoc()
        Exit Sub

printErrorHandler:
        If Err.Number = 30010 Then
            MsgBox(Err.Description) ' "There Are No Results To Print"
        Else
            MsgBox("Error : " & Err.Description & vbCrLf & "Error Number : " & Err.Number)
        End If
        Exit Sub

    End Sub




    Public Sub helpMenuAbout_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles helpMenuAbout.Click

        On Error Resume Next

        FRMabout.ShowDialog()

    End Sub

    Private Sub searchButt_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles searchButt.Click

        On Error Resume Next

        Dim queryStr As String
        If LISTtables.SelectedIndex > -1 Then

            If TXTsearch.Text <> "" Then

                If LISTfields.SelectedItems.Count > 0 Then

                    queryStr = Trim(TXTsearch.Text)
                    MODdbMethods.searchDB(VB6.GetItemString(LISTtables, LISTtables.SelectedIndex), VB6.GetItemString(LISTfields, LISTfields.SelectedIndex), queryStr)

                Else

                    MsgBox("Choose At Least One Field To Search, or Choose ""All""")

                End If
            Else

                MsgBox("Please Choose A Phrase To Search For")
                Me.TXTsearch.Focus()
            End If
        Else
            MsgBox("No File Open")
            TXTsearch.Focus()
        End If

        setDataGridColumnWidths()

    End Sub

    'UPGRADE_WARNING: Event LISTtables.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
    Private Sub LISTtables_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles LISTtables.SelectedIndexChanged

        On Error Resume Next

        Dim sSelectedField As String
        If LISTtables.SelectedIndex > -1 Then
            ''''''''''''' CREATE FIELDS LIST BOX and COLUMN HEADERS FOR SEARCH RESULTS

            'UPGRADE_WARNING: Couldn't resolve default property of object getPref(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            sSelectedField = getPref("", "DefaultSearchField")

            MODdbMethods.setFieldsList(VB6.GetItemString(LISTtables, LISTtables.SelectedIndex), sSelectedField)

        End If

    End Sub

    Public Sub fileQuit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles fileQuit.Click

        End

    End Sub



    ' Take the focus away from the last edited row so it is forced to update -------------------------------------------------------------------------

    Private Sub removeFocusFromGrid()

        On Error Resume Next

        Throw New NotImplementedException

    End Sub

    ' Events -------------------------------------------------------------------------------------------------------------------------

    ' Import File ---------------------------------------------------------------------------------------------------------------------

    Public Sub fileImport_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles fileImport.Click

        On Error Resume Next

        'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
        With CommonDialogOpen

            'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            .Filter = "Excel Files (.xls)|*.xls|All Files|*.*"

            'UPGRADE_WARNING: The CommonDialog CancelError property is not supported in Visual Basic .NET. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8B377936-3DF7-4745-AA26-DD00FA5B9BE1"'
            .ShowDialog()

            DLGimport.init(.FileName)

        End With

    End Sub

    ' Web menu events ---------------------------------------------------------------------------------------------------------------

    Public Sub WebDeleteSavedUpdate_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles WebDeleteSavedUpdate.Click

        On Error Resume Next

        Dim fso As Scripting.FileSystemObject

        fso = New Scripting.FileSystemObject

        If Not fso.FileExists(MODweb.sRemoteUpdateRecordsFilePath) Then

            MsgBox("There are no records to delete")

            Exit Sub

        End If

        If MsgBox("Are you sure you want to delete the records ?", MsgBoxStyle.OkCancel) <> MsgBoxResult.Ok Then Exit Sub

        fso.CopyFile(MODweb.sRemoteUpdateRecordsFilePath, MODweb.sRemoteUpdateBackupDirPath & "records_" & getUniqueTimeStamp())

        fso.DeleteFile(MODweb.sRemoteUpdateRecordsFilePath, False)

        'UPGRADE_NOTE: Object fso may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
        fso = Nothing

    End Sub

    Public Sub WebUpdateAllRecords_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles WebUpdateAllRecords.Click

        On Error Resume Next

        removeFocusFromGrid()

        updateAllRecords()

    End Sub

    Public Sub WebUpdateFromFile_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles WebUpdateFromFile.Click

        On Error Resume Next

        MODweb.updateFromFile()

    End Sub

    Public Sub WebUpdateLater_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles WebUpdateLater.Click

        On Error Resume Next

        removeFocusFromGrid()

        MODweb.exportRecordsForUpdate()

    End Sub

    ' Tool menu events --------------------------------------------------------------------------------------------------------

    Public Sub toolsCalculator_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles toolsCalculator.Click

        On Error Resume Next

        Dim X As Integer
        X = Shell("Calc.exe", 1)

    End Sub

    Public Sub ToolSendMail_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ToolSendMail.Click

        MODtools.sendMailToBroker()

    End Sub


    Public Sub toolsPreferences_Click(ByVal eventSender As Object, ByVal eventArgs As System.EventArgs) Handles toolsPreferences.Click

        On Error Resume Next

        DLGpreferences.ShowDialog()

    End Sub

    ' Data grid events ---------------------------------------------------------------------------------------------------------------

    Private Sub DataGrid_AfterColEdit(ByVal eventSender, ByVal eventArgs) ' Handles DataGrid.AfterColEdit
        Dim Adodc1 As Object

        On Error Resume Next

        If doRemoteUpdate Then

            isNewRecord = False
            'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            MODweb.buildUpdateStatement(Adodc1.Recordset, "SET")

        End If

    End Sub

    Private Sub DataGrid_BeforeColUpdate(ByVal eventSender, ByVal eventArgs) ' Handles DataGrid.BeforeColUpdate
        Dim Adodc1 As Object

        On Error Resume Next

        doRemoteUpdate = True
        Dim newValue As Object

        ' Check to make sure that the user does not update the 'uniqueID' field ----------------------------------------------------------------
        ' If the condition returns true thrn cancel the update --------------------------------------------------------------------------

        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        If Adodc1.Recordset.Fields(eventArgs.colIndex).Name = "uniqueID" Then

            eventArgs.cancel = 1
            doRemoteUpdate = False

            Exit Sub

        End If

        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        MODweb.buildUpdateStatement(Adodc1.Recordset, "WHERE")

    End Sub

    Private Sub DataGrid_BeforeUpdate(ByVal eventSender, ByVal eventArgs) 'Handles DataGrid.BeforeUpdate
        Dim Adodc1 As Object

        On Error Resume Next

        'UPGRADE_WARNING: Couldn't resolve default property of object Adodc1.Recordset. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        Adodc1.Recordset("UPDATE") = Today & " " & TimeOfDay

    End Sub

    Private Sub DataGrid_MouseDownEvent(ByVal eventSender, ByVal eventArgs) 'Handles DataGrid.MouseDownEvent

        On Error Resume Next

        Dim Xtwips, selectedRow, Ytwips As Short
        If eventArgs.button And VB6.MouseButtonConstants.RightButton Then


            'If VB6.TwipsPerPixelX < 1 Then Xtwips = 1 Else Xtwips = VB6.TwipsPerPixelX
            'If VB6.TwipsPerPixelY < 1 Then Ytwips = 1 Else Ytwips = VB6.TwipsPerPixelY

            'If DataGrid.ColContaining(eventArgs.x / Xtwips) > -1 Then

            '    Exit Sub

            'End If

            'selectedRow = DataGrid.RowContaining(eventArgs.y / Ytwips)
            'DataGrid.Row = selectedRow
            'UPGRADE_ISSUE: Form method FRMmain.PopupMenu was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
            Throw New NotImplementedException("Should show the Edit menu as a context menu")

        End If

    End Sub

    Private Sub FRMmain_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        On Error Resume Next

        removeFocusFromGrid()

        If Not bRemoteSaved Then

            If MsgBox("You have made changes to the local database, but have not updated the remote database" & vbCrLf & vbCrLf & "Is this OK ?", MsgBoxStyle.OkCancel, "Unsaved Changes") <> 1 Then
                e.Cancel = True
                Exit Sub
            End If
        End If
    End Sub
End Class